<?php
    @header("Content-Type:text/html;charset=utf-8");

    @include_once("conn.php");

    if(!isset($_POST["user"])){
        $obj = array();
        $obj["status"] = false;
        $obj["msg"] = "请传入完整参数";
        $json = json_encode($obj);
        exit($json);
    }


    $user = $_POST["user"];

     // 查询
     $sql = " select s.id,s.user,g.goodsId,g.goodsName,g.goodsImg,g.goodsPrice,s.buyNum,s.isChecked from `shoppingcar` as s,`goodslist` as g where s.gid = g.goodsId and user = '$user'";

     // 执行mysql语句
     $result = mysqli_query($conn,$sql);
     // print_r($result);
 
     $obj = array();
     if($result){
 
 
         $list = array();
         // 解析数据  => 赋值给变量 $item  =>  有数据,循环解析  没有数据(null) =>跳出循环
         while($item = mysqli_fetch_assoc($result)){
             // 预处理
             $item["subtotal"] = round($item["goodsPrice"] * $item["buyNum"],2);
             $item["isChecked"] = $item["isChecked"]*1;
             array_push($list,$item);
         }
 
         // print_r($list);
 
         $obj["status"] = true;
         $obj["msg"] = "OK";
         $obj["list"] = $list;
 
     }else{
         $obj["status"] = false;
         $obj["msg"] = "sql语句有误";
         $obj["sql"] = $sql;
     }
 
     echo json_encode($obj);
 


?>